package pooltest;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import test.vo.DeptVO;

public class TestMybatis {
	
	static SqlSessionFactory factory;
	
	public static void mm() {
		try {
			
			if (null == factory){
				Reader r = Resources.getResourceAsReader("pooltest/configuration.xml");
				SqlSessionFactoryBuilder build = new SqlSessionFactoryBuilder();
				factory = build.build(r);
				r.close();
				System.out.println("Create pool!!");
			}
			SqlSession ss = factory.openSession();
			
			System.out.println(ss.toString());

			ArrayList<Object> list = (ArrayList<Object>) ss.selectList("selectDept");

			for (int i = 0; i < list.size(); i++) {
				HashMap map = (HashMap)list.get(i);
				System.out.println(map.get("foo") + "\t");
			}
			
			ss.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}